package com.lovo.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.system.dto.PurchaseMesDto;
import com.lovo.system.mapper.PurchaseMesMapper;
import com.lovo.system.service.IPurchaseMesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PurchaseMesServiceImpl extends ServiceImpl<PurchaseMesMapper, PurchaseMesDto> implements IPurchaseMesService {

    @Autowired
    PurchaseMesMapper purchaseMesMapper;

    @Override
    public IPage<PurchaseMesDto> info(int curPage, int pageSize, String startTime, String endTime, String name) {
        QueryWrapper qw = new QueryWrapper();
        if (startTime!=null && !startTime.equals("")){
            qw.ge("purchase_mes_date",startTime);
        }
        if (endTime!=null && !endTime.equals("")){
            qw.le("purchase_mes_date",endTime);
        }
        if (name!=null && !name.equals("")){
            qw.like("purchase_mes_name",name);
        }
        return purchaseMesMapper.selectPage(new Page<>(curPage,pageSize),qw);
    }

    @Override
    public int insertPurchaseMes(PurchaseMesDto purchaseMesDto) {
        purchaseMesMapper.insert(purchaseMesDto);
        return purchaseMesDto.getPurchaseMesId();
    }

}
